<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>controlP5 : : ControlBehavior</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="stylesheet.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
document.getElementsByTagName('html')[0].className = 'isjs';

function toggle(dt) 
{ 
  var display, dd=dt; 
  /* get dd */ 
  do{ dd = dd.nextSibling } while(dd.tagName!='DD'); 
  toOpen =!dd.style.display; 
  dd.style.display = toOpen? 'block':'' 
  dt.getElementsByTagName('span')[0].innerHTML 
    = toOpen? '-':'+' ; 
} 
</script>
</head>
<body>
<div id="container">
		<div id="header">
		<a href="./index.htm"><img src="./docuImages/title.jpg" /></a>
		</div>
	<div class="content">
		<h1>ControlBehavior</h1>
		<dl><dt class="key">description</dt><dd class="value">control behavior is an abstract class and can be extended, update() has to be
 implemented. how to use ControlBehavior please see the ControlP5behavior example in the
 examples folder.</dd></dl>
			
			<div class="toggleList example">
				<dl><dt onclick="toggle(this)"><span>+</span>Example</dt>
					<dd><pre>import controlP5.*;


ControlP5 controlP5;

int myColorBackground = color(0,0,0);

int sliderValue = 100;

void setup() {
  size(400,400);
  frameRate(30);
  controlP5 = new ControlP5(this);
  controlP5.addSlider("sliderValue",0,255,128,100,200,10,100);
  controlP5.addSlider("slider",100,200,128,100,160,100,10);
  controlP5.controller("slider").setBehavior(new SineBehavior());
  controlP5.addBang("bang",40,10,40,40);
  controlP5.controller("bang").setBehavior(new TimedEvent());
}

void draw() {
  background(myColorBackground);
  fill(sliderValue);
  rect(0,0,width,100);
}

void slider(float theColor) {
  myColorBackground = color(theColor);
  println("a slider event. setting background to "+theColor);
  //controlP5.controller("sliderValue").setValue(theColor);
}

void controlEvent(ControlEvent theControlEvent) {
  if(theControlEvent.isController()) {
    println("controller : "+theControlEvent.controller().id());
  }
}


class SineBehavior extends ControlBehavior {
  float a = 0;
  
  public void update() {
    a += 0.1;
    setValue(sin(a)*50  + 150);
  }
}


class TimedEvent extends ControlBehavior {
  
  long myTime;
  
  int interval = 200;
  
  public TimedEvent() {
    reset();
  }
  
  void reset() {
    myTime = millis() + interval;
  }
  
  public void update() {
    if(millis()>myTime) {
      setValue(1);
      reset();
    }
  }
  
}

</pre></dd>
				</dl>
			</div>
			
			
			
			<dl><dt class="key">constructors</dt><dd class="value"><pre>ControlBehavior();
</pre></dd></dl>
			
			
			
			
			
			
			
			<!-- METHODS:BEGIN -->
			
       <dl class="noborder"><dt>Methods</dt></dl>
       <dl><dt class="key"><a href="controlbehavior_method_controller.htm">controller ( )</a></dt><dd class="value">returns the controller this behavior is connected to.</dd></dl>
<dl><dt class="key"><a href="controlbehavior_method_isactive.htm">isActive ( )</a></dt><dd class="value">check if the behavior is active or not.</dd></dl>
<dl><dt class="key"><a href="controlbehavior_method_setactive.htm">setActive ( )</a></dt><dd class="value">(de)activate the behavior.</dd></dl>
<dl><dt class="key"><a href="controlbehavior_method_setvalue.htm">setValue ( )</a></dt><dd class="value">set the value of the controller.</dd></dl>
<dl><dt class="key"><a href="controlbehavior_method_update.htm">update ( )</a></dt><dd class="value">when extending ControlBehavior, update() has to be overwritten.</dd></dl>
<dl><dt class="key"><a href="controlbehavior_method_value.htm">value ( )</a></dt><dd class="value">get the value of the controller this behavior is connected to.</dd></dl>

   
			<!-- METHODS:END -->
			<div class="separator">
			<dl><dt class="key">usage</dt><dd class="value">Web & Application</dd></dl>
			</div>
			<div class="separator">
			<dl><dt class="key">related</dt><dd class="value"><ul></ul></dd></dl>
			</div>
	</div>
	<div id="footer">
	<p>by andreas schlegel (<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/" target="_blank">cc</a>) 2007, <a href="http://www.sojamo.de" target="_blank">sojamo</a>.</p>
	</div>
</div>
</body>
</html>


